package demo;

import java.util.Scanner;


public class meituan1 {

        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int n = sc.nextInt();
            int[] a = new int[n];

            long sum = 0; // 用long避免大数组求和溢出
            int max = 0;
            for (int i = 0; i < n; i++) {
                a[i] = sc.nextInt();
                sum += a[i];
                if (a[i] > max) {
                    max = a[i];
                }
            }

            // 计算maxBit：数组最大值的二进制位数（0的位数为1）
            int maxBit = (max == 0) ? 1 : Integer.toBinaryString(max).length();

            // 计算mask：所有元素的按位与
            int mask = a[0];
            for (int i = 1; i < n; i++) {
                mask &= a[i];
            }

            // 计算allowedBits：~mask的低maxBit位（限制x的位数）
            int maxBitMask = (1 << maxBit) - 1; // maxBit位全1的掩码
            int allowedBits = (~mask) & maxBitMask;

            // 结果
            long maxSum = sum + allowedBits;
            int minX = allowedBits;

            System.out.println(maxSum + " " + minX);
        }

}
